package com.huirui.server.pojo.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Data
@Schema(description = "秒杀活动DTO")
public class SeckillDto {

    @Schema(description = "商品ID", example = "1001")
    @NotNull(message = "商品ID不能为空")
    private Long productId;

    @Schema(description = "秒杀开始时间", example = "2025-11-11T10:00:00")
    @NotNull(message = "秒杀开始时间不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
//    @FutureOrPresent(message = "秒杀开始时间不能早于当前时间")
    private LocalDateTime seckillStartTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "秒杀结束时间", example = "2025-11-11T23:59:59")
    @NotNull(message = "秒杀结束时间不能为空")
    @Future(message = "秒杀结束时间必须晚于当前时间")
    private LocalDateTime seckillEndTime;

    @Schema(description = "秒杀状态（0-未开始，1-进行中，2-已结束）", example = "0")
    @NotNull(message = "状态不能为空")
    @Min(value = 0, message = "状态值不能小于0")
    @Max(value = 2, message = "状态值不能大于2")
    private Integer status;

    @Schema(description = "秒杀商品规格列表")
    @NotEmpty(message = "秒杀商品规格列表不能为空")
    @Valid // 用于校验嵌套对象
    private List<SeckillProductSpecificationDto> seckillProductSpecificationDtoList;

    @Data
    @Schema(description = "秒杀商品规格DTO")
    public static class SeckillProductSpecificationDto {

        @Schema(description = "商品规格ID", example = "2001")
        @NotNull(message = "商品规格ID不能为空")
        private Long productSpecificationId;

        @Schema(description = "秒杀价格", example = "99.99")
        @NotNull(message = "秒杀价格不能为空")
        @DecimalMin(value = "0.01", message = "秒杀价格必须大于0")
        @Digits(integer = 10, fraction = 2, message = "秒杀价格格式错误，最多10位整数，2位小数")
        private BigDecimal seckillPrice;

        @Schema(description = "秒杀库存数量", example = "100")
        @NotNull(message = "库存数量不能为空")
        @Min(value = 1, message = "库存数量不能小于1")
        private Long stock;
    }
}